-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ssh: Add bannerfun to the server role #9149
base: master
Are you sure you want to change the base?
ssh: Add bannerfun to the server role #9149
Conversation
CT Test Results 2 files 29 suites 19m 39s ⏱️ Results for commit f60efc4. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
5f14347
to
65d5b9f
Compare
65d5b9f
to
c5c7b12
Compare
bannerfun/1 enables the server to send a SSH_MSG_USERAUTH_BANNER at the beginning of user authentication, immediately after receiving the first SSH_MSG_USERAUTH_BANNER
Update the existing renegotiation tests to include a bannerfun so there is a check that the erlang server sending a banner is compatible with openssh.
abe8576
to
f60efc4
Compare
@u3s I have force pushed to fix the conflict in ssh.hrl. The branch is now rebased with the latest master. |
@@ -213,3 +215,26 @@ retry_fun(User, Reason, #data{ssh_params = #ssh{opts = Opts, | |||
ok | |||
end. | |||
|
|||
maybe_send_banner(D0 = #data{ssh_params = #ssh{userauth_banner_sent = false} = Ssh}, User) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use maybe to simplify code? something like this:
maybe_send_banner(D0 = #data{ssh_params = #ssh{userauth_banner_sent = false} = Ssh}, User) ->
Opts = Ssh#ssh.opts,
BannerFun = maps:get(bannerfun, Opts, undefined),
maybe
true ?= is_function(BannerFun, 1),
BannerTxt = BannerFun(User),
true ?= is_binary(BannerTxt) andalso byte_size(BannerTxt)>0, % Ignore bad banner texts
Banner = #ssh_msg_userauth_banner{message = BannerText,
language = <<>>},
D = D0#data{ssh_params = Ssh#ssh{userauth_banner_sent = true}},
ssh_connection_handler:send_msg(Banner, D)
else
_ -> D0
end;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that if you want. Other option is to have the default bannerfun being fun(V) -> <<>> end
Then the implementation can be something like this:
maybe_send_banner(D0 = #data{ssh_params = #ssh{userauth_banner_sent = false} = Ssh}, User) ->
BannerFun = ?GET_OPT(bannerfun, Ssh#ssh.opts),
case BannerFun(User) of
BannerText when is_binary(BannerText), byte_size(BannerText) > 0 ->
Banner = #ssh_msg_userauth_banner{message = BannerText,
language = <<>>},
D = D0#data{ssh_params = Ssh#ssh{userauth_banner_sent = true}},
ssh_connection_handler:send_msg(Banner, D);
_ ->
D0
end;
maybe_send_banner(D, _) ->
D.
Which one do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your proposal more :-)
bannerfun/1 enables the server to send a SSH_MSG_USERAUTH_BANNER at the beginning of user authentication, immediately after receiving the first SSH_MSG_USERAUTH_BANNER